package com.example.a2205douyin.live;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.a2205douyin.R;
import com.example.a2205douyin.entity.GiftEntity;

public class GiftLayout extends LinearLayout {
    private ImageView ivUsername,ivGiftname;
    private TextView tvUsername,tvGiftname,tvCount;
    public GiftLayout(Context context) {
        super(context);
    }

    public GiftLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = LayoutInflater.from(context).inflate(R.layout.gift_layout, null);
        ivUsername = view.findViewById(R.id.iv_username);
        ivGiftname = view.findViewById(R.id.iv_giftname);
        tvUsername = view.findViewById(R.id.tv_username);
        tvGiftname = view.findViewById(R.id.tv_giftname);
        tvCount = view.findViewById(R.id.tv_count);
        //目的让布局显示
        addView(view);
    }

    public GiftLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public GiftLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }
    //给各个控件进行赋值
    public void loadIcon(String url){
        //显示用户头像
        Glide.with(getContext()).load(url).circleCrop().into(ivUsername);
    }
    public void loadName(String name){
        //显示用户名称
        tvUsername.setText(name+"");
    }
    public void loadGift(GiftEntity.DataBean dataBean){
        tvGiftname.setText("送"+dataBean.getGiftname());
        Glide.with(getContext()).load(dataBean.getGiftpath()).circleCrop().into(ivGiftname);
    }
    public void loadCount(int count){
        tvCount.setText("X "+count);
    }
}
